package com.avic.rong.userOrder.viewHolder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.payUtil.JavaPayUtil;
import com.avic.rong.payUtil.PayVo;
import com.avic.rong.shoppingCar.activity.ShoppingCarActivity;
import com.avic.rong.userOrder.activity.MoreEvaluateActivity;
import com.avic.rong.userOrder.event.InformUpdate;
import com.avic.rong.userOrder.activity.BankPayActivity;
import com.avic.rong.userOrder.activity.FaPiaoDetailsActivity;
import com.avic.rong.userOrder.activity.LookOrderAddressActivity;
import com.avic.rong.userOrder.activity.MineOrderActivity;
import com.avic.rong.userOrder.activity.OrderConfirmActivity;
import com.avic.rong.userOrder.activity.OrderDetailsActivity;
import com.avic.rong.userOrder.activity.OrderDetailsPXActivity;
import com.avic.rong.userOrder.activity.OrderEvaluateActivity;
import com.avic.rong.userOrder.activity.PayAgreenActivity;
import com.avic.rong.userOrder.activity.PaySucceedActivity;
import com.avic.rong.userOrder.activity.ShopPayActivity;
import com.avic.rong.userOrder.activity.UpdateFaPiaoActivity;
import com.avic.rong.userOrder.activity.UploadProofActivity;
import com.avic.rong.userOrder.adapter.PayWayAdapter;
import com.avic.rong.userOrder.api.AddCarApi;
import com.avic.rong.userOrder.api.BuyAgainApi;
import com.avic.rong.userOrder.api.ConfirmReceiptApi;
import com.avic.rong.userOrder.api.GetOrderTracesApi;
import com.avic.rong.userOrder.api.OrderCancelApi;
import com.avic.rong.userOrder.api.OrderCancelPXApi;
import com.avic.rong.userOrder.api.OrderDeleteApi;
import com.avic.rong.userOrder.api.OrderDeletePXApi;
import com.avic.rong.userOrder.api.OrderFinishApi;
import com.avic.rong.userOrder.api.OrderRecoverApi;
import com.avic.rong.userOrder.api.PaySubmitApi;
import com.avic.rong.userOrder.api.PaySubmitPXApi;
import com.avic.rong.userOrder.api.ToPayApi;
import com.avic.rong.userOrder.api.ToPayPXApi;
import com.avic.rong.userOrder.bean.AllOrderListBean;
import com.avic.rong.userOrder.bean.BuyAgainBean;
import com.avic.rong.userOrder.bean.PayWayBean;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DateUtils;
import com.avic.rong.utils.DeviceUtils;
import com.avic.rong.utils.DialogCustom;
import com.avic.rong.utils.GlideUtils;
import com.avic.rong.utils.MoneyShowUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.ToastTools;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.example.minato.minastore.utils.AppUtils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by XinEr on 2019/7/27.
 * Describe:
 */
public class OrderListViewHolder extends RecyclerView.ViewHolder {
    private TextView tv_deal_complete;
    private ImageView iv_goods_pic;
    private LinearLayout ll_goods_name;
    private TextView tv_update_fapiao;
    private TextView tv_cancel_order;
    private TextView tv_look_fapiao;
    private TextView tv_urge_fahuo;
    private TextView tv_look_wuliu;
    private TextView tv_pingjia;
    private TextView tv_pay;
    private TextView tv_look_address;
    private TextView tv_confirm_shouhuo;
    private TextView tv_again_buy;
    private TextView tv_goods_titls;
    private TextView tv_goods_price;
    private TextView tv_goods_subtitle;
    private TextView tv_goods_number;
    private TextView tv_goods_type_number;
    private TextView tv_goods_reall_price;
    private TextView tv_order_type;
    private TextView tv_order_tel;
    private TextView tv_upload_proof;
    private TextView tv_order_finish;
    private TextView tv_recover_order;
    private LinearLayout ll_root;
    public static String ORDER_ID = "order_id";
    public static String ORDER_SN = "order_sn";
    private int COMMENT_FORCODE = 6;


    private PopupWindow popupWindow;
    private RelativeLayout rl_close;
    private ImageView iv_goods_error;
    private RelativeLayout rl_goods_error;
    private ImageView iv_fapiao_error;
    private RelativeLayout rl_fapiao_error;
    private ImageView iv_not;
    private RelativeLayout rl_not;
    private ImageView iv_qita;
    private RelativeLayout rl_qita;
    private TextView tv_kaolv;
    private TextView tv_submit;

    private TextView tv_apply_fapiao;
    private RelativeLayout rl_alone;
    private TextView tv_goods_tel;
    private TextView tv_goods_type;


    //多图
    private ImageView iv_product_one;
    private TextView tv_product_one_number;
    private TextView tv_morestatus_one;
    private RelativeLayout rl_goods_one;
    private ImageView iv_product_two;
    private TextView tv_product_two_number;
    private TextView tv_morestatus_two;
    private RelativeLayout rl_goods_two;
    private ImageView iv_product_three;
    private TextView tv_product_three_number;
    private TextView tv_morestatus_three;
    private RelativeLayout rl_goods_three;
    private TextView tv_goods_num;
    private LinearLayout ll_more_products;
    private TextView tv_goods_type_one;
    private TextView tv_goods_type_two;
    private TextView tv_goods_type_three;
    private TextView tv_goods_tel_one;
    private TextView tv_goods_tel_two;
    private TextView tv_goods_tel_three;


    private TextView tv_status;
    private int SELECT_CHECK = -1;
    private Context context;
    //再次购买
    private int AGAINBUY = 100;

    private List<PayWayBean.PaymentListBean> paymentList = new ArrayList<>();

    private PayWayAdapter payWayAdapter;

    private boolean isAgreement = true;//勾选用户协议

    private int payId = -1;
    private JavaPayUtil javaPayUtil;

    private int orderType = -1;
    private int orderId = -1;
    private String orderSn = null;

    private AllOrderListBean.OrderListBean.ItemsViewBean itemsViewBean;
    private AllOrderListBean.OrderListBean orderListBean;


    private LinearLayout ll_pic_tag;
    private LinearLayout ll_pic_tag_one;
    private LinearLayout ll_pic_tag_two;
    private LinearLayout ll_pic_tag_three;
    private EditText et_use_yue;
    private int orderRecoverPayWay=-1;

    //列表更新
    private int LIST_UPDATE=1000;

    public OrderListViewHolder(@NonNull View itemView) {
        super(itemView);
        tv_deal_complete = itemView.findViewById(R.id.tv_deal_complete);
        iv_goods_pic = itemView.findViewById(R.id.iv_goods_pic);
        ll_goods_name = itemView.findViewById(R.id.ll_goods_name);
        tv_update_fapiao = itemView.findViewById(R.id.tv_update_fapiao);
        tv_cancel_order = itemView.findViewById(R.id.tv_cancel_order);
        tv_look_fapiao = itemView.findViewById(R.id.tv_look_fapiao);
        tv_look_wuliu = itemView.findViewById(R.id.tv_look_wuliu);
        tv_pingjia = itemView.findViewById(R.id.tv_pingjia);
        tv_look_address = itemView.findViewById(R.id.tv_look_address);
        tv_pay = itemView.findViewById(R.id.tv_pay);
        tv_confirm_shouhuo = itemView.findViewById(R.id.tv_confirm_shouhuo);
        tv_again_buy = itemView.findViewById(R.id.tv_again_buy);
        tv_goods_titls = itemView.findViewById(R.id.tv_goods_titls);
        tv_goods_price = itemView.findViewById(R.id.tv_goods_price);
        tv_goods_subtitle = itemView.findViewById(R.id.tv_goods_subtitle);
        tv_goods_number = itemView.findViewById(R.id.tv_goods_number);
        tv_goods_type_number = itemView.findViewById(R.id.tv_goods_type_number);
        tv_goods_reall_price = itemView.findViewById(R.id.tv_goods_reall_price);
        tv_urge_fahuo = itemView.findViewById(R.id.tv_urge_fahuo);
        ll_root = itemView.findViewById(R.id.ll_root);
        ll_goods_name = itemView.findViewById(R.id.ll_goods_name);
        tv_deal_complete = itemView.findViewById(R.id.tv_deal_complete);
        tv_order_type = itemView.findViewById(R.id.tv_order_type);
        tv_order_tel = itemView.findViewById(R.id.tv_order_tel);
        tv_upload_proof = itemView.findViewById(R.id.tv_upload_proof);
        tv_recover_order = itemView.findViewById(R.id.tv_recover_order);
        tv_order_finish = itemView.findViewById(R.id.tv_order_finish);
        tv_goods_tel = itemView.findViewById(R.id.tv_goods_tel);
        tv_status = itemView.findViewById(R.id.tv_status);
        tv_apply_fapiao = itemView.findViewById(R.id.tv_apply_fapiao);
        rl_alone = itemView.findViewById(R.id.rl_alone);
        tv_goods_type = itemView.findViewById(R.id.tv_goods_type);


        //多图
        iv_product_one = itemView.findViewById(R.id.iv_product_one);
        tv_product_one_number = itemView.findViewById(R.id.tv_product_one_number);
        tv_morestatus_one = itemView.findViewById(R.id.tv_morestatus_one);
        rl_goods_one = itemView.findViewById(R.id.rl_goods_one);
        iv_product_two = itemView.findViewById(R.id.iv_product_two);
        tv_product_two_number = itemView.findViewById(R.id.tv_product_two_number);
        tv_morestatus_two = itemView.findViewById(R.id.tv_morestatus_two);
        rl_goods_two = itemView.findViewById(R.id.rl_goods_two);
        iv_product_three = itemView.findViewById(R.id.iv_product_three);
        tv_product_three_number = itemView.findViewById(R.id.tv_product_three_number);
        tv_morestatus_three = itemView.findViewById(R.id.tv_morestatus_three);
        rl_goods_three = itemView.findViewById(R.id.rl_goods_three);
        tv_goods_num = itemView.findViewById(R.id.tv_goods_num);
        ll_more_products = itemView.findViewById(R.id.ll_more_products);
        tv_goods_type_one = itemView.findViewById(R.id.tv_goods_type_one);
        tv_goods_type_two = itemView.findViewById(R.id.tv_goods_type_two);
        tv_goods_type_three = itemView.findViewById(R.id.tv_goods_type_three);

        tv_goods_tel_one = itemView.findViewById(R.id.tv_goods_tel_one);
        tv_goods_tel_two = itemView.findViewById(R.id.tv_goods_tel_two);
        tv_goods_tel_three = itemView.findViewById(R.id.tv_goods_tel_three);


        ll_pic_tag = itemView.findViewById(R.id.ll_pic_tag);
        ll_pic_tag_one = itemView.findViewById(R.id.ll_pic_tag_one);
        ll_pic_tag_two = itemView.findViewById(R.id.ll_pic_tag_two);
        ll_pic_tag_three = itemView.findViewById(R.id.ll_pic_tag_three);


    }

    public void setData(final AllOrderListBean.OrderListBean orderListBean, final Context context, String biaoZhunImg, String fileServer) {
        this.context = context;
        this.orderListBean = orderListBean;
        List<AllOrderListBean.OrderListBean.ItemsViewBean> itemsView = orderListBean.getItemsView();

//        GlideUtils.loaderImage(context, itemsViewBean.getGoodsImg(), iv_goods_pic);
        tv_order_tel.setText(orderListBean.getOrderSn());


        if (!TextUtils.isEmpty(orderListBean.getOrderType() + "") && orderListBean.getOrderType() > 0) {

            //订单类型 全部：0，软件：1，元器件 2，标准：4，培训：5，会员服务：8
            if (orderListBean.getOrderType() == 1) {
                tv_goods_type_number.setText("软件共" + orderListBean.getCount() + "件");
            } else if (orderListBean.getOrderType() == 2) {
                tv_goods_type_number.setText("元器件共" + orderListBean.getCount() + "件");
            } else if (orderListBean.getOrderType() == 4) {
                tv_goods_type_number.setText("标准共" + orderListBean.getCount() + "件");
            } else if (orderListBean.getOrderType() == 5) {
                tv_goods_type_number.setText("培训共" + orderListBean.getCount() + "件");
            } else if (orderListBean.getOrderType() == 8) {
                tv_goods_type_number.setText("会员服务服务共" + orderListBean.getCount() + "件");
            }
        }

        tv_goods_reall_price.setText("实付金额： ¥" + orderListBean.getOrderAmount() + "");


        if (itemsView.size() == 1) {
            itemsViewBean = itemsView.get(0);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    if (itemsViewBean.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_goods_pic,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBean.getGoodsImg(), iv_goods_pic,10);
                    }
                    iv_goods_pic.setVisibility(View.VISIBLE);
                    ll_pic_tag.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel.setText(keywords);
                    tv_goods_type.setText(catName);
                    ll_pic_tag.setVisibility(View.VISIBLE);
                    iv_goods_pic.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_goods_pic);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_goods_pic,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_goods_pic,10);
                    iv_goods_pic.setVisibility(View.VISIBLE);
                    ll_pic_tag.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel.setText(keywords);
                    tv_goods_type.setText(catName);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_goods_pic,10);
                    iv_goods_pic.setVisibility(View.VISIBLE);
                    ll_pic_tag.setVisibility(View.VISIBLE);
                }

            }


            if (orderListBean.getOrderType() == 5) {

                if (itemsViewBean.getCourseType() == 0) {
//                    courseType = "点播课";
//
//                    默认图片：wwwStatic /img/online_default.jpg
                    if (TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                        GlideUtils.loaderHanldeRoundImage(context, AppUtils.BASE_URL + "static/img/online_default.jpg", iv_goods_pic,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, fileServer + itemsViewBean.getGoodsImg(), iv_goods_pic,10);
                    }


                }
                if (itemsViewBean.getCourseType() == 1) {
//                    courseType = "直播课";
//
//                    wwwStatic /img/online_default.jpg
                    if (TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                        GlideUtils.loaderHanldeRoundImage(context, AppUtils.BASE_URL + "static/img/online_default.jpg", iv_goods_pic,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, fileServer + itemsViewBean.getGoodsImg(), iv_goods_pic,10);
                    }
                }
                if (itemsViewBean.getCourseType() == 2) {
//                    courseType = "线下课程";
//                    默认图片：wwwStatic /img/offline_default.jpg
                    if (TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                        GlideUtils.loaderHanldeRoundImage(context, AppUtils.BASE_URL + "static/img/offline_default.jpg", iv_goods_pic,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, fileServer + itemsViewBean.getGoodsImg(), iv_goods_pic,10);

                    }
                }
                if (itemsViewBean.getCourseType() == 3) {
//
//                    默认图片：wwwStatic /img/customized_default.jpg
                    if (TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                        GlideUtils.loaderHanldeRoundImage(context, AppUtils.BASE_URL + "static/img/customized_default.jpg", iv_goods_pic,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, fileServer + itemsViewBean.getGoodsImg(), iv_goods_pic,10);

                    }
                }


//                if (TextUtils.isEmpty(itemsViewBean.getGoodsImg())){
//
//                    GlideUtils.loaderImage(context, AppUtils.BASE_URL+"static/img/online_default.jpg",iv_goods_pic);
//                }else {
//                    GlideUtils.loaderImage(context,fileServer+itemsViewBean.getGoodsImg(),iv_goods_pic);
//                }
            }


            tv_goods_titls.setText(itemsViewBean.getGoodsName());
            tv_goods_price.setText("¥" + itemsViewBean.getGoodsPrice());

            tv_goods_number.setText("x" + itemsViewBean.getGoodsNumber());

            if (orderListBean.getOrderType() != 5) {

                String subtitle = orderSubtitle(itemsViewBean.getSkuName());
                if (subtitle != null) {
                    tv_goods_subtitle.setText(subtitle);
                }
            } else {
                if (TextUtils.isEmpty(itemsViewBean.getSkuName())) {
                    return;
                }
                tv_goods_subtitle.setText(itemsViewBean.getSkuName());
            }
            if (!TextUtils.isEmpty(itemsViewBean.getAttrShow())) {
                tv_status.setText(itemsViewBean.getAttrShow());
                tv_status.setVisibility(View.VISIBLE);
            }


            rl_alone.setVisibility(View.VISIBLE);
            ll_more_products.setVisibility(View.GONE);

        } else if (itemsView.size() == 2) {
            itemsViewBean = itemsView.get(0);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    if (itemsViewBean.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_product_one,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBean.getGoodsImg(), iv_product_one,10);
                    }
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel_one.setText(keywords);
                    tv_goods_type_one.setText(catName);
                    ll_pic_tag_one.setVisibility(View.VISIBLE);
                    iv_product_one.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_one);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_one,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_product_one,10);
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel_one.setText(keywords);
                    tv_goods_type_one.setText(catName);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_one,10);
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.VISIBLE);
                }

            }


            tv_product_one_number.setText("x" + itemsViewBean.getGoodsNumber());
            if (!TextUtils.isEmpty(itemsViewBean.getAttrShow())) {
                tv_morestatus_one.setText(itemsViewBean.getAttrShow());
                tv_morestatus_one.setVisibility(View.VISIBLE);
            }


            AllOrderListBean.OrderListBean.ItemsViewBean itemsViewBeanTwo = itemsView.get(1);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBeanTwo.getGoodsImg())) {
                    if (itemsViewBeanTwo.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanTwo.getGoodsImg(), iv_product_two,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBeanTwo.getGoodsImg(), iv_product_two,10);
                    }
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBeanTwo.getKeywords();
                    String catName = itemsViewBeanTwo.getCatName();
                    tv_goods_tel_two.setText(keywords);
                    tv_goods_type_two.setText(catName);
                    ll_pic_tag_two.setVisibility(View.VISIBLE);
                    iv_product_two.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_two);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_two,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBeanTwo.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanTwo.getGoodsImg(), iv_product_two,10);
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBeanTwo.getKeywords();
                    String catName = itemsViewBeanTwo.getCatName();
                    tv_goods_tel_two.setText(keywords);
                    tv_goods_type_two.setText(catName);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_two,10);
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.VISIBLE);
                }

            }


            tv_product_two_number.setText("x" + itemsViewBeanTwo.getGoodsNumber());
            if (!TextUtils.isEmpty(itemsViewBeanTwo.getAttrShow())) {
                tv_morestatus_two.setText(itemsViewBeanTwo.getAttrShow());
                tv_morestatus_two.setVisibility(View.VISIBLE);
            }


            rl_alone.setVisibility(View.GONE);
            ll_more_products.setVisibility(View.VISIBLE);

            rl_goods_one.setVisibility(View.VISIBLE);
            rl_goods_two.setVisibility(View.VISIBLE);
        } else if (itemsView.size() >= 3) {
            itemsViewBean = itemsView.get(0);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    if (itemsViewBean.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_product_one,6);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBean.getGoodsImg(), iv_product_one,6);
                    }
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel_one.setText(keywords);
                    tv_goods_type_one.setText(catName);
                    ll_pic_tag_one.setVisibility(View.VISIBLE);
                    iv_product_one.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_one);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_one,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBean.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBean.getGoodsImg(), iv_product_one,10);
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBean.getKeywords();
                    String catName = itemsViewBean.getCatName();
                    tv_goods_tel_one.setText(keywords);
                    tv_goods_type_one.setText(catName);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_one,10);
                    iv_product_one.setVisibility(View.VISIBLE);
                    ll_pic_tag_one.setVisibility(View.VISIBLE);
                }

            }


            tv_product_one_number.setText("x" + itemsViewBean.getGoodsNumber());

            if (!TextUtils.isEmpty(itemsViewBean.getAttrShow())) {
                tv_morestatus_one.setText(itemsViewBean.getAttrShow());
                tv_morestatus_one.setVisibility(View.VISIBLE);
            }


            AllOrderListBean.OrderListBean.ItemsViewBean itemsViewBeanTwo = itemsView.get(1);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBeanTwo.getGoodsImg())) {
                    if (itemsViewBeanTwo.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanTwo.getGoodsImg(), iv_product_two,6);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBeanTwo.getGoodsImg(), iv_product_two,6);
                    }
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBeanTwo.getKeywords();
                    String catName = itemsViewBeanTwo.getCatName();
                    tv_goods_tel_two.setText(keywords);
                    tv_goods_type_two.setText(catName);
                    ll_pic_tag_two.setVisibility(View.VISIBLE);
                    iv_product_two.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_two);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_two,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBeanTwo.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanTwo.getGoodsImg(), iv_product_two,10);
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBeanTwo.getKeywords();
                    String catName = itemsViewBeanTwo.getCatName();
                    tv_goods_tel_two.setText(keywords);
                    tv_goods_type_two.setText(catName);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_two,10);
                    iv_product_two.setVisibility(View.VISIBLE);
                    ll_pic_tag_two.setVisibility(View.VISIBLE);
                }

            }


            tv_product_two_number.setText("x" + itemsViewBeanTwo.getGoodsNumber());

            if (!TextUtils.isEmpty(itemsViewBeanTwo.getAttrShow())) {
                tv_morestatus_two.setText(itemsViewBeanTwo.getAttrShow());
                tv_morestatus_two.setVisibility(View.VISIBLE);
            }


            AllOrderListBean.OrderListBean.ItemsViewBean itemsViewBeanThree = itemsView.get(2);

            if (orderListBean.getOrderType() == 4) {
                if (!TextUtils.isEmpty(itemsViewBeanThree.getGoodsImg())) {
                    if (itemsViewBeanThree.getGoodsImg().contains("rongrong.")) {
                        GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanThree.getGoodsImg(), iv_product_three,10);
                    } else {
                        GlideUtils.loaderHanldeRoundImage(context, biaoZhunImg + itemsViewBeanThree.getGoodsImg(), iv_product_three,10);
                    }
                    iv_product_three.setVisibility(View.VISIBLE);
                    ll_pic_tag_three.setVisibility(View.GONE);
                } else {
                    String keywords = itemsViewBeanThree.getKeywords();
                    String catName = itemsViewBeanThree.getCatName();
                    tv_goods_tel_three.setText(keywords);
                    tv_goods_type_three.setText(catName);
                    ll_pic_tag_three.setVisibility(View.VISIBLE);
                    iv_product_three.setVisibility(View.VISIBLE);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_three);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_three,10);
                }
            } else {
                if (!TextUtils.isEmpty(itemsViewBeanThree.getGoodsImg())) {
                    GlideUtils.loaderHanldeRoundImage(context, itemsViewBeanThree.getGoodsImg(), iv_product_three,10);
                    iv_product_three.setVisibility(View.VISIBLE);
                    ll_pic_tag_three.setVisibility(View.GONE);
                } else {
                    //默认图
//                GlideUtils.loaderImage(context, R.mipmap.common_bg, iv_goods_pic);
                    String keywords = itemsViewBeanThree.getKeywords();
                    String catName = itemsViewBeanThree.getCatName();
                    tv_goods_tel_three.setText(keywords);
                    tv_goods_type_three.setText(catName);
//                    Glide.with(context).load(R.mipmap.common_bg).into(iv_product_three);
                    GlideUtils.loaderHanldeRoundImageResource(context, R.mipmap.common_bg, iv_product_three,10);
                    iv_product_three.setVisibility(View.VISIBLE);
                    ll_pic_tag_three.setVisibility(View.VISIBLE);
                }

            }

            tv_product_three_number.setText("x" + itemsViewBeanThree.getGoodsNumber());

            if (!TextUtils.isEmpty(itemsViewBeanThree.getAttrShow())) {
                tv_morestatus_three.setText(itemsViewBeanThree.getAttrShow());
                tv_morestatus_three.setVisibility(View.VISIBLE);
            }


            rl_alone.setVisibility(View.GONE);
            ll_more_products.setVisibility(View.VISIBLE);

            rl_goods_one.setVisibility(View.VISIBLE);
            rl_goods_two.setVisibility(View.VISIBLE);
            rl_goods_three.setVisibility(View.VISIBLE);
            //我的订单列表-商品种类小于等于2时，应该不展示查看更多按钮，大于等于3时，才会展示
            tv_goods_num.setVisibility(View.VISIBLE);
        }

//        var skuNames = JSON.parse(item.skuName);
//        var skuName ;
//        var str = '';
//        for ( var j =0;j<skuNames.length;j++){
//            skuName = skuNames[j];
//            for(var key in skuName){
//                str += ' '+skuName[key] + ' ';
//            }
//        }
//        Gson gson = new Gson();
////        String sku = gson.toJson(itemsViewBean.getSkuName());


        final int orderStatus = orderListBean.getOrderStatus();
        int payStatus = orderListBean.getPayStatus();
        int shippingStatus = orderListBean.getShippingStatus();
        if (orderStatus == 5) {
            //交易成功
           /* tv_pingjia.setVisibility(View.VISIBLE);
            tv_look_fapiao.setVisibility(View.VISIBLE);
            tv_again_buy.setVisibility(View.VISIBLE);

            tv_look_wuliu.setVisibility(View.GONE);
            tv_confirm_shouhuo.setVisibility(View.GONE);
            tv_urge_fahuo.setVisibility(View.GONE);
            tv_update_fapiao.setVisibility(View.GONE);
            tv_cancel_order.setVisibility(View.GONE);
            tv_pay.setVisibility(View.GONE);*/
            tv_deal_complete.setText("交易完成 | ");
            tv_deal_complete.setVisibility(View.VISIBLE);
        } else if (orderStatus == 2) {
            // 交易关闭
            tv_deal_complete.setText("交易关闭 | ");
            tv_deal_complete.setVisibility(View.VISIBLE);
        } else {
            if (payStatus == 3) {
                //处理中
                tv_order_type.setText("处理中");
                tv_order_type.setVisibility(View.VISIBLE);
            }
            if (payStatus < 2) {
                //待付款
               /* tv_update_fapiao.setVisibility(View.VISIBLE);
                tv_cancel_order.setVisibility(View.VISIBLE);
                tv_pay.setVisibility(View.VISIBLE);

                tv_look_fapiao.setVisibility(View.GONE);
                tv_look_wuliu.setVisibility(View.GONE);
                tv_confirm_shouhuo.setVisibility(View.GONE);
                tv_pingjia.setVisibility(View.GONE);
                tv_again_buy.setVisibility(View.GONE);
                tv_urge_fahuo.setVisibility(View.GONE);*/
                tv_order_type.setText("待付款");
                tv_order_type.setVisibility(View.VISIBLE);
            }
            if (payStatus == 2 && (shippingStatus == 0 || shippingStatus == 3)) {
                //待发货
               /* tv_look_fapiao.setVisibility(View.VISIBLE);
                tv_urge_fahuo.setVisibility(View.VISIBLE);

                tv_look_wuliu.setVisibility(View.GONE);
                tv_confirm_shouhuo.setVisibility(View.GONE);
                tv_pingjia.setVisibility(View.GONE);
                tv_again_buy.setVisibility(View.GONE);
                tv_update_fapiao.setVisibility(View.GONE);
                tv_cancel_order.setVisibility(View.GONE);
                tv_pay.setVisibility(View.GONE);*/
                tv_order_type.setText("待发货");
                tv_order_type.setVisibility(View.VISIBLE);
            }
            if (shippingStatus == 1) {
                //待收货
               /* tv_look_fapiao.setVisibility(View.VISIBLE);
                tv_look_wuliu.setVisibility(View.VISIBLE);
                tv_confirm_shouhuo.setVisibility(View.VISIBLE);

                tv_pingjia.setVisibility(View.GONE);
                tv_again_buy.setVisibility(View.GONE);
                tv_update_fapiao.setVisibility(View.GONE);
                tv_cancel_order.setVisibility(View.GONE);
                tv_pay.setVisibility(View.GONE);
                tv_urge_fahuo.setVisibility(View.GONE);*/
                tv_order_type.setText("待收货");
                tv_order_type.setVisibility(View.VISIBLE);
            }
        }

        int orderType = orderListBean.getOrderType();
        String payId = (String) orderListBean.getPayId();
        int invId = orderListBean.getInvId();
        int shippingId = orderListBean.getShippingId();
        int type = orderListBean.getType();


        if (orderType != 5) {
            if (payStatus < 2 && !"1".equals(payId)) {
//                取消订单
                tv_cancel_order.setVisibility(View.VISIBLE);
            }
            if (!TextUtils.isEmpty(invId + "") && payStatus == 2 && invId > 0) {
//                查看发票\

                tv_look_fapiao.setVisibility(View.VISIBLE);
            }
            if (orderStatus == 0 && orderType != 2 && orderType != 3) {
//                去付款
                tv_pay.setVisibility(View.VISIBLE);
            }
            if (orderStatus == 1 && payStatus <= 1) {
                if (!"1".equals(payId) && !"4".equals(payId)) {
//                    去付款
                    tv_pay.setVisibility(View.VISIBLE);
                }
                if ("4".equals(payId)) {
//                    上传支付凭证
                    tv_upload_proof.setVisibility(View.VISIBLE);
                }
            }
            if (shippingStatus == 3) {
//                催促发货(请与网站运营人员联系，联系电话4006-618-301)
                tv_urge_fahuo.setVisibility(View.VISIBLE);
            }
            if (shippingStatus == 0 && payStatus == 2 && orderStatus != 5) {
//                催促发货(请与网站运营人员联系，联系电话4006-618-301)
                tv_urge_fahuo.setVisibility(View.VISIBLE);
            }
            if (shippingStatus == 1) {
//                确认收货
                tv_confirm_shouhuo.setVisibility(View.VISIBLE);
            }
            if (orderStatus != 5 && shippingId == 4) {
//                查看取货地址
                tv_look_address.setVisibility(View.VISIBLE);
//                tv_look_wuliu.setVisibility(View.VISIBLE);
            }
            if (orderStatus == 5 || orderStatus == 2) {
//                再次购买
                tv_again_buy.setVisibility(View.VISIBLE);
            }
            if (orderStatus == 5) {
//                评价
                tv_pingjia.setVisibility(View.VISIBLE);
            }
        } else {//培训
            if (orderStatus != 2) {
//                if (!TextUtils.isEmpty(invId + "")) {
////                    查看发票
//                    tv_look_fapiao.setVisibility(View.VISIBLE);
//                }
                if (payStatus == 0 && !"2".equals(payId)) {
//                    去付款
                    tv_pay.setVisibility(View.VISIBLE);
                }
                if ("2".equals(payId)&&orderStatus!=5) {
//                    上传付款凭证
                    tv_upload_proof.setVisibility(View.VISIBLE);
                }
                if (payStatus != 1 && payStatus != 2 && payStatus != 3) {
//                    取消订单
                    tv_cancel_order.setVisibility(View.VISIBLE);
                }
            } else if (type == 2) {
                if ("2".equals(payId)) {
//                    恢复订单(payWay:2)
                    orderRecoverPayWay=2;
                    tv_recover_order.setVisibility(View.VISIBLE);
                } else {
//                    恢复订单(payWay:0)
                    orderRecoverPayWay=0;
                    tv_recover_order.setVisibility(View.VISIBLE);
                }
            }

            if (itemsView.get(0)==null)  return;
            AllOrderListBean.OrderListBean.ItemsViewBean itemsViewBean = itemsView.get(0);
            if (payStatus == 2&&itemsViewBean.getTaxType()>0) {
                if (!TextUtils.isEmpty(invId + "") && invId > 0) {
//                        查看发票
                    tv_look_fapiao.setVisibility(View.VISIBLE);
                } else {
//                        申请发票
                    tv_apply_fapiao.setVisibility(View.VISIBLE);
                }
            }/* else if (payStatus == 0 || payStatus == 2) {
//                    修改发票
                tv_update_fapiao.setVisibility(View.VISIBLE);
            }*/


        }

        //查看发票
        tv_look_fapiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(context, FaPiaoDetailsActivity.class);
                intent.putExtra("order_id", orderListBean.getOrderId() + "");
                intent.putExtra("order_type", orderListBean.getOrderType() + "");
                context.startActivity(intent);
               /* if (!Constant.getToken().isEmpty()) {
                    Map<String, String> paramsBody = new HashMap<>();
                    paramsBody.put("courseId", "4368");

                    paramsBody.put("token",Constant.getToken());
                    paramsBody.put("amount","2");
                    paramsBody.put("orderType",orderType+"");
                    paramsBody.put("orderType",orderType+"");
                    final MineOrderActivity mineOrderActivity = (MineOrderActivity) context;
                    //获取支付方式
                    final OrderSubmitPXApi orderSubmitPXApi = new OrderSubmitPXApi(mineOrderActivity, simpleOnNextListenerOrderSubmitPX);
                    orderSubmitPXApi.setCache(false);
                    orderSubmitPXApi.setMap(paramsBody);
                    HttpManager.getInstance().doHttpDeal(orderSubmitPXApi);


                }*/
            }
        });
        //修改发票
        tv_update_fapiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UpdateFaPiaoActivity.class);
                intent.putExtra("order_id", orderListBean.getOrderId() + "");
                intent.putExtra("order_type", orderListBean.getOrderType() + "");
                context.startActivity(intent);
            }
        });
        //取消订单
        tv_cancel_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (orderType != 5) {
                    cancleOrder(context, orderListBean.getOrderId() + "");
                } else {
                    cancleOrderPX(context, orderListBean.getOrderSn() + "");
                }

            }
        });
        //item点击
        ll_root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                orderListBean.setBiaoZhunImg(biaoZhunImg);
                orderListBean.setFileServer(fileServer);
//                if (itemsView.size()>1){
////                    Bundle bundle = new Bundle();
////                    bundle.putSerializable("more_goods_order",orderListBean);
//
//                    Intent intent = new Intent(context, MoreEvaluateActivity.class);
//                    intent.putExtra("more_goods_order",orderListBean);
//                    context.startActivity(intent);
//                }else if(itemsView.size()==1){
//                    Intent intent = new Intent(context, OrderEvaluateActivity.class);
//                    intent.putExtra("goods_order",orderListBean );
//                    intent.putExtra("good_bean",orderListBean);
//                    context.startActivity(intent);
//                }


                if (orderType != 5) {
                    Intent intent = new Intent(context, OrderDetailsActivity.class);
                    intent.putExtra(ORDER_ID, itemsViewBean.getOrderId() + "");

                    if (itemsView.size()>1){
                        intent.putExtra("more_goods_order",orderListBean);
                    }else if(itemsView.size()==1){
                        intent.putExtra("goods_order",itemsViewBean );
                        intent.putExtra("good_bean",orderListBean);
                    }

                    intent.putExtra(OrderDetailsActivity.ORDER_LIST_JUMP, "order_list");
                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                } else {
                    Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                    intent.putExtra(ORDER_SN, orderListBean.getOrderSn() + "");
                    intent.putExtra(OrderDetailsPXActivity.ORDER_LIST_JUMP, "order_list");
                    ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                }

            }
        });
        //催促发货   (请与网站运营人员联系，联系电话4006-618-301)
        tv_urge_fahuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogCustom.showDoubleDialog(context, "", "请与网站运营人员联系，联系电话4006-618-301", "否", "是", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {
                        callPhone("4006-618-301");
                    }

                    @Override
                    public void leftButtonClicked() {

                    }
                });
//                ToastTools.showToast(context, "请与网站运营人员联系，联系电话4006-618-301");
            }
        });
        //删除订单
        tv_deal_complete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DialogCustom.showDoubleDialog(context, "", "确认删除订单？", "取消", "确认", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {
                        if (orderType != 5) {
                            dealOrder(context, itemsViewBean.getOrderId() + "");
                        } else {
                            dealOrderPX(context, orderListBean.getOrderSn() + "");
                        }
                    }

                    @Override
                    public void leftButtonClicked() {
                    }
                });


            }
        });
        //查看物流
        tv_look_wuliu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lookWuLiu(context, orderListBean.getOrderId() + "");
            }
        });
        //再次购买
        tv_again_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                againBuyResq(context, orderListBean.getOrderId() + "");
            }
        });
        //完成订单
        tv_order_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                orderFinish(context, orderListBean.getOrderId() + "");
            }
        });
        //上传凭证
        tv_upload_proof.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UploadProofActivity.class);
                intent.putExtra("order_id", orderListBean.getOrderId() + "");
                intent.putExtra("order_sn", orderListBean.getOrderSn() + "");
                intent.putExtra("orderType", orderListBean.getOrderType() + "");
                context.startActivity(intent);
            }
        });
        //评价
        tv_pingjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                orderListBean.setBiaoZhunImg(biaoZhunImg);
                orderListBean.setFileServer(fileServer);
                if (itemsView.size()>1){
//                    Bundle bundle = new Bundle();
//                    bundle.putSerializable("more_goods_order",orderListBean);

                    Intent intent = new Intent(context, MoreEvaluateActivity.class);
                    intent.putExtra("more_goods_order",orderListBean);
                    context.startActivity(intent);
                }else if(itemsView.size()==1){
                    Intent intent = new Intent(context, OrderEvaluateActivity.class);
                    intent.putExtra("goods_order",itemsViewBean );
                    intent.putExtra("good_bean",orderListBean);
                    context.startActivity(intent);
                }

            }
        });
        //查看收货地址
        tv_look_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LookOrderAddressActivity.class);
                context.startActivity(intent);
            }
        });
        //去支付
        tv_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (DateUtils.isFastDoubleClick())return;
                    if (orderType != 5) {
                        //去支付
                        toPay(orderType, orderListBean.getOrderId());
                    } else {
                        //培训去支付

                        toPayPX(orderType, orderListBean.getOrderSn());
                    }


            }
        });
        //确认收货
        tv_confirm_shouhuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                configmOrder();

            }
        });
        //恢复订单
        tv_recover_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DialogCustom.showDoubleDialog(context, "提示", "您确定要恢复订单吗？", "取消", "确定", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {
                        if (orderRecoverPayWay==-1) return;
                        orderRecover(orderListBean.getOrderSn(),orderRecoverPayWay);
                    }

                    @Override
                    public void leftButtonClicked() {

                    }
                });

            }
        });
//        申请发票
        tv_apply_fapiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UpdateFaPiaoActivity.class);
                intent.putExtra("order_sn", orderListBean.getOrderSn() + "");
                intent.putExtra("order_id", orderListBean.getOrderId() + "");
                intent.putExtra("order_money", orderListBean.getOrderAmount() + "");
                ((MineOrderActivity)context).startActivityForResult(intent,LIST_UPDATE);
            }
        });


    }

    private void orderRecover(String orderSn, int orderRecoverPayWay) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {

            Map<String, String> paramsBody = new HashMap<>();
            if (TextUtils.isEmpty(orderSn)) {
                ToastTools.showToast(context, "没有获取到订单编号");
                return;
            }
            paramsBody.put("orderNumber", orderSn);
            //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
            //支付方式 0微信；1支付宝；2银行卡
          /*  if (payId.equals("2")) {
                paramsBody.put("payWay", 0 + "");
            } else if (payId.equals("3")) {
                paramsBody.put("payWay", 1 + "");
            } else if (payId.equals("4")) {
                paramsBody.put("payWay", 2 + "");
            }*/
            paramsBody.put("payWay", orderRecoverPayWay + "");
            paramsBody.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            final OrderRecoverApi orderRecoverApi = new OrderRecoverApi(mineOrderActivity, simpleOnNextListenerOrderRecover);
            orderRecoverApi.setCache(false);
            orderRecoverApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(orderRecoverApi);


        }
    }

    //恢复订单
    HttpOnNextListener simpleOnNextListenerOrderRecover = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.ORDER_RECOVER_INFORM);
            EventBus.getDefault().post(informUpdate);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());

        }
    };

    private String orderSubtitle(String orderSkuName) {
        JSONArray jsonArray = null;
        String skuName = "";
        try {
            if (TextUtils.isEmpty(orderSkuName)) {
                return null;
            }
            jsonArray = new JSONArray(orderSkuName);
            StringBuffer paramsSb = new StringBuffer("");
            StringBuffer moreParamsb = new StringBuffer("");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                Iterator<String> keys = jsonObject.keys();
                String key = "";
                while (keys.hasNext()) {//遍历JSONObject

                    key = (String) keys.next().toString();

                    if (null != key && !"".equals(key)) {

                        String value = (String) jsonObject.get(key);
                        if (jsonArray.length()>1){
//                            skuName = value +"; ";

                            paramsSb.append(value + " ; ");
                        }else {
                            paramsSb.append(value);
                        }

                    }

                }


            }
            if (jsonArray.length()>1){
                moreParamsb.append(paramsSb.deleteCharAt(paramsSb.length() - 2));
                return moreParamsb.toString();
            }else {
                return paramsSb.toString();
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    private void configmOrder() {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        Map<String, String> map = new HashMap<>();
        if (orderListBean.getOrderId() == -1) return;
        map.put("orderId", orderListBean.getOrderId() + "");
        map.put("token", SharedPreferencesUtil.getInstance(context).getLogintoken());
        final ConfirmReceiptApi confirmReceiptApi = new ConfirmReceiptApi(mineOrderActivity, simpleOnNextListenerConfimOrder);
        confirmReceiptApi.setCache(false);
        confirmReceiptApi.setMap(map);
        HttpManager.getInstance().doHttpDeal(confirmReceiptApi);
    }

    //确认收货
    HttpOnNextListener simpleOnNextListenerConfimOrder = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            ToastTools.showToast(context, "收货成功");
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.CONFIRM_SHOUHUO_INFORM);
            EventBus.getDefault().post(informUpdate);

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());

        }
    };

    private void toPayPX(int orderType, String orderSn) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {

            Map<String, String> paramsBody = new HashMap<>();
            if (TextUtils.isEmpty(orderSn)) {
                ToastTools.showToast(context, "没有获取到订单编号");
                return;
            }
            this.orderSn = orderSn;
            this.orderType = orderType;
//            paramsBody.put("orderId", orderId+"");
            paramsBody.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            //获取支付方式
            final ToPayPXApi toPayPXApi = new ToPayPXApi(mineOrderActivity, simpleOnNextListenerPayWayPX);
            toPayPXApi.setCache(false);
            toPayPXApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(toPayPXApi);


        }
    }

    private void toPay(int orderType, int orderId) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            if (orderId == -1) {
                ToastTools.showToast(context, "没有获取到支付ID");
                return;
            }
            this.orderId = orderId;
            this.orderType = orderType;
            paramsBody.put("orderId", orderId + "");
            paramsBody.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            //获取支付方式
            final ToPayApi toPayApi = new ToPayApi(mineOrderActivity, simpleOnNextListenerPayWay);
            toPayApi.setCache(false);
            toPayApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(toPayApi);


        }
    }

    //培训获取支付方式
    HttpOnNextListener simpleOnNextListenerPayWayPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }

            PayWayBean data = (PayWayBean) subjects.getData();
            paymentList.addAll(data.getPaymentList());
            //选择支付
            selectPay(data);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };
    //获取支付方式
    HttpOnNextListener simpleOnNextListenerPayWay = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }

            PayWayBean data = (PayWayBean) subjects.getData();
            paymentList.addAll(data.getPaymentList());
            //选择支付
            selectPay(data);


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //培训订单提交
    HttpOnNextListener simpleOnNextListenerOrderSubmitPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }


        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    private void selectPay(PayWayBean data) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.select_pay_way_layout, null);
        RelativeLayout rl_close = (RelativeLayout) inflate.findViewById(R.id.rl_close);
//        final ImageView chat_btn = (ImageView) inflate.findViewById(R.id.chat_btn);
//        final ImageView ali_btn = (ImageView) inflate.findViewById(R.id.ali_btn);
//        final ImageView zhuanzhang_btn = (ImageView) inflate.findViewById(R.id.zhuanzhang_btn);
//        final ImageView yue_btn = (ImageView) inflate.findViewById(R.id.yue_btn);
//        final ImageView shop_pay_btn = (ImageView) inflate.findViewById(R.id.shop_pay_btn);
        RecyclerView recy_list = inflate.findViewById(R.id.recy_list);
        final ImageView iv_agree = (ImageView) inflate.findViewById(R.id.iv_agree);
        final TextView tv_submit_order = (TextView) inflate.findViewById(R.id.tv_submit_order);
        final TextView tv_pay_agreen = (TextView) inflate.findViewById(R.id.tv_pay_agreen);
//        final TextView tv_order_price = (TextView) inflate.findViewById(R.id.tv_order_price);
        et_use_yue = (EditText) inflate.findViewById(R.id.et_use_yue);
        final LinearLayout ll_use_yue = (LinearLayout) inflate.findViewById(R.id.ll_use_yue);
        if (orderListBean != null) {
            tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(orderListBean.getOrderAmount() + ""));
        }

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        recy_list.setLayoutManager(linearLayoutManager);
        payWayAdapter = new PayWayAdapter(context, paymentList);
        recy_list.setAdapter(payWayAdapter);
        payWayAdapter.setOrderType(orderType);

        //只有ordertype==4才有余额支付
        if (orderType != 5) {
            if (orderType == 4) {
                ll_use_yue.setVisibility(View.VISIBLE);
            } else {
                ll_use_yue.setVisibility(View.GONE);
            }
        } else {
            ll_use_yue.setVisibility(View.GONE);
        }


        payWayAdapter.setYueMoney(data.getUserMoney());
        payWayAdapter.setOrderPrice(orderListBean.getOrderAmount() + "");
        payWayAdapter.notifyDataSetChanged();


        iv_agree.setSelected(isAgreement);
//        chat_btn.setRJCPSelected(true);
        commonPop(inflate);
        //关闭按钮
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogCustom.showDoubleDialog(context, "", "确认放弃付款？", "确认离开", "继续支付", new DialogCustom.CustomDialogDouble() {
                    @Override
                    public void rightButtonClicked() {

                    }

                    @Override
                    public void leftButtonClicked() {
                        if (orderType != 5) {
                            Intent intent = new Intent(context, OrderDetailsActivity.class);
                            intent.putExtra(ORDER_ID, orderId + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        } else {
                            Intent intent = new Intent(context, OrderDetailsPXActivity.class);
                            intent.putExtra(ORDER_SN, orderSn + "");

                            ((Activity) context).startActivityForResult(intent, COMMENT_FORCODE);
                        }
                        popupWindow.dismiss();
                    }
                });
            }
        });
        et_use_yue.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if (TextUtils.isEmpty(s.toString())){
                    tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber(orderListBean.getOrderAmount() + ""));
                    return;
                }
                if ((Double.parseDouble(orderListBean.getOrderAmount() + "")-Double.parseDouble(s.toString()))<0){
                    ToastTools.showToast(context,"使用余额的金额应不能大于付款金额");
                    et_use_yue.setText(orderListBean.getOrderAmount() + "");
                }else if ((data.getUserMoney()-Double.parseDouble(s.toString()))<0){
                    ToastTools.showToast(context,"使用余额的金额应不能大于所剩余额");
                    et_use_yue.setText(data.getUserMoney()+"");
                }else {
                    if (payId!=-1){
                        tv_submit_order.setText("确认付款 ¥" + MoneyShowUtils.dealNumber((Double.parseDouble(orderListBean.getOrderAmount() + "")-Double.parseDouble(s.toString()))+""));
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        //列表点击事件
        payWayAdapter.setOnClickItem(new PayWayAdapter.OnClickItem() {
            @Override
            public void OnClickListion(View view, int postion) {
                if (paymentList != null && paymentList.size() > 0) {
                    payId = paymentList.get(postion).getPayId();
                }
                payWayAdapter.setmSelectedPos(postion);
                if (payId == 5) {

                    et_use_yue.setText(MoneyShowUtils.dealNumber(orderListBean.getOrderAmount()+""));

                } else {
                    et_use_yue.setText("");
                }
                payWayAdapter.notifyDataSetChanged();
            }
        });
        Double finalOrderPriceSubmit = orderListBean.getOrderAmount();

        //支付协议
        tv_pay_agreen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PayAgreenActivity.class);
                context.startActivity(intent);
            }
        });
//        chat_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                chat_btn.setRJCPSelected(true);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//                Toast.makeText(OrderConfirmActivity.this, "点击了", Toast.LENGTH_SHORT).show();
//            }
//        });
//        ali_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(true);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        zhuanzhang_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(true);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        yue_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(true);
//                shop_pay_btn.setRJCPSelected(false);
//            }
//        });
//        shop_pay_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                chat_btn.setRJCPSelected(false);
//                ali_btn.setRJCPSelected(false);
//                zhuanzhang_btn.setRJCPSelected(false);
//                yue_btn.setRJCPSelected(false);
//                shop_pay_btn.setRJCPSelected(true);
//            }
//        });
        //同意条款
        iv_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAgreement = !isAgreement;
                iv_agree.setSelected(isAgreement);
            }
        });
        //付款提交
        tv_submit_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String useYue = et_use_yue.getText().toString().trim();
                String submitMoney = tv_submit_order.getText().toString().trim();
                submitMoney = submitMoney.replace("确认付款 ¥", "");
               /* if (Double.parseDouble(submitMoney) <= 0) {
                    if (payId == 2 || payId == 3 || payId == 4 || payId == 6) {
                        ToastTools.showLongToast(context, "支付金额为0，请选择余额支付");
                        return;
                    }

                }*/
                if (!iv_agree.isSelected()) {
                    ToastTools.showLongToast(context, "同意条款才能进行支付");
                    return;
                } else if (payId != -1 && payId == 5) {
                   /* if (!TextUtils.isEmpty(useYue)) {
                        ToastTools.showLongToast(context, "选择余额支付后无需填写余额");
                        return;
                    }else*/ if (Double.parseDouble(submitMoney) > data.getUserMoney()) {
                        ToastTools.showLongToast(context, "余额不足请充值或选择其他支付方式！");
                        return;
                    }
                } else if (payId != -1 && payId != 5) {
                    if (!TextUtils.isEmpty(useYue) && !TextUtils.isEmpty(orderListBean.getOrderAmount() + "")) {
                        if (Double.parseDouble(useYue) > Double.parseDouble(orderListBean.getOrderAmount() + "")) {
                            ToastTools.showLongToast(context, "您选择了混合的支付方式，请填写正确的金额");
                            return;
                        }
                    }

                } else if (data.getUserMoney() <= 0) {
                    useYue = "0.00";
                } else if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                    ToastTools.showLongToast(context, "请选择支付方式！");
                    return;
                } else if (data.getUserMoney() < Double.parseDouble(submitMoney)) {
                    ToastTools.showLongToast(context, "您当前余额不足！");
                    return;
                }

                if (orderType != 5) {
                    if (payWayAdapter.getBalancePayId() == 5 || payId == 5) {
                        paySubmit(useYue);
                    } else {
                        paySubmit(useYue);
                    }

                } else {
                    if (payWayAdapter.getBalancePayId() == 5 || payId == 5) {
                        paySubmitPX(useYue);
                    } else {
                        paySubmitPX(useYue);

                    }
                }

            }
        });


    }

    private void paySubmitPX(String useYue) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            if (TextUtils.isEmpty(orderSn)) {
                ToastTools.showToast(context, "没有获取到支付ID");
                return;
            }
            paramsBody.put("orderNumber", orderSn);
            paramsBody.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                return;
            }
            paramsBody.put("payId", payId + "");
            //支付提交
            final PaySubmitPXApi paySubmitPXApi = new PaySubmitPXApi(mineOrderActivity, simpleOnNextListenerPaySubmitPX);
            paySubmitPXApi.setCache(false);
            paySubmitPXApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(paySubmitPXApi);


        }

    }

    private void paySubmit(String use_yue) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> paramsBody = new HashMap<>();
            if (orderId == -1) {
                ToastTools.showToast(context, "没有获取到支付ID");
                return;
            }
            paramsBody.put("orderId", orderId + "");
            paramsBody.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            if (payWayAdapter.getBalancePayId() == -1 && payId == -1) {
                return;
            }
            paramsBody.put("payId", payId + "");
            if (!TextUtils.isEmpty(use_yue)) {
                paramsBody.put("balance", use_yue);
            } else {
                paramsBody.put("balance", 0 + "");
            }

            //支付提交
            final PaySubmitApi paySubmitApi = new PaySubmitApi(mineOrderActivity, simpleOnNextListenerPaySubmit);
            paySubmitApi.setCache(false);
            paySubmitApi.setMap(paramsBody);
            HttpManager.getInstance().doHttpDeal(paySubmitApi);


        }
    }

    //培训支付提交
    HttpOnNextListener simpleOnNextListenerPaySubmitPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            popupWindow.dismiss();
            if ((PayVo) subjects.getData() != null) {
                final PayVo payVo = (PayVo) subjects.getData();
                if (javaPayUtil == null) {
                    javaPayUtil = new JavaPayUtil(context, new JavaPayUtil.PaySuccessCallBack() {
                        @Override
                        public void paySuccess() {
//                            Intent intent = new Intent();
//                            setResult(MEMBER_REFRESH, intent);
//                            finish();
//                            ToastTools.showToast(OrderConfirmActivity.this,"支付成功");
//                            new Intent(OrderConfirmActivity.this,)
                            if (orderId != -1) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            //  pay_state  1  成功   2   失败
                            Intent intent = new Intent(context, PaySucceedActivity.class);
                            intent.putExtra("order_sn", orderSn + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            intent.putExtra("pay_state", 1 + "");
                            context.startActivity(intent);
                        }

                        @Override
                        public void expertPaySuccess(String consultType) {

                        }

                        @Override
                        public void payCancel() {
                            if (orderId != -1) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            //  pay_state  1  成功   2   失败
                            Intent intent = new Intent(context, PaySucceedActivity.class);
                            intent.putExtra("order_sn", orderSn + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            intent.putExtra("pay_state", 2 + "");
                            context.startActivity(intent);
                        }
                    });
                }

                //orderType用来区分是否有余额支付
                if (orderType != -1) {
                    payVo.setOrderType(orderType);
                }
                String payId = payVo.getPayId();
                int payID = Integer.parseInt(payId);
                //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                if (payID == 2) {
                    javaPayUtil.payByWay(payVo, "WeChat");
                } else if (payID == 3) {
                    javaPayUtil.payByWay(payVo, "Alipay");
                } else if (payID == 4) {
                    Intent intent = new Intent(context, BankPayActivity.class);
                    intent.putExtra("order_sn", orderSn + "");
                    intent.putExtra("orderType", orderType + "");
                    context.startActivity(intent);

                } else if (payWayAdapter.getBalancePayId() == 5 || payID == 5) {
                    if (orderId == -1) {
                        ToastTools.showToast(context, "没有获取到订单ID");
                        return;
                    }
                    Intent intent = new Intent(context, PaySucceedActivity.class);
                    intent.putExtra("order_sn", orderSn + "");
                    intent.putExtra("order_type", orderType);
                    context.startActivity(intent);
                } else if (payID == 6) {
                    Intent intent = new Intent(context, ShopPayActivity.class);
                    context.startActivity(intent);
                }

            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };
    //支付提交
    HttpOnNextListener simpleOnNextListenerPaySubmit = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            paymentList.clear();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            popupWindow.dismiss();
            if ((PayVo) subjects.getData() != null) {
                final PayVo payVo = (PayVo) subjects.getData();
                if (javaPayUtil == null) {
                    javaPayUtil = new JavaPayUtil(context, new JavaPayUtil.PaySuccessCallBack() {
                        @Override
                        public void paySuccess() {
//                            Intent intent = new Intent();
//                            setResult(MEMBER_REFRESH, intent);
//                            finish();
//                            ToastTools.showToast(OrderConfirmActivity.this,"支付成功");
//                            new Intent(OrderConfirmActivity.this,)
                            if (orderId == -1) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            Intent intent = new Intent(context, PaySucceedActivity.class);
                            intent.putExtra("order_id", orderId + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            context.startActivity(intent);
                        }

                        @Override
                        public void expertPaySuccess(String consultType) {

                        }

                        @Override
                        public void payCancel() {
                            if (orderId == -1) {
                                ToastTools.showToast(context, "没有获取到支付ID");
                                return;
                            }
                            Intent intent = new Intent(context, PaySucceedActivity.class);
                            intent.putExtra("order_id", orderId + "");
                            intent.putExtra("order_type", payVo.getOrderType());
                            context.startActivity(intent);
                        }
                    });
                }

                //orderType用来区分是否有余额支付
                if (orderType != -1) {
                    payVo.setOrderType(orderType);
                }
                String payId = payVo.getPayId();
                int payID = Integer.parseInt(payId);
                //payId  2  微信支付   3     支付宝     4    银行汇款/转账     6   到店支付     5   余额支付
                if (payID == 2) {
                    javaPayUtil.payByWay(payVo, "WeChat");
                } else if (payID == 3) {
                    javaPayUtil.payByWay(payVo, "Alipay");
                } else if (payID == 4) {
                    Intent intent = new Intent(context, BankPayActivity.class);
                    intent.putExtra("order_id", orderId + "");
                    intent.putExtra("orderType", orderType + "");
                    context.startActivity(intent);

                } else if (payWayAdapter.getBalancePayId() == 5 || payID == 5) {
                    if (orderId == -1) {
                        ToastTools.showToast(context, "没有获取到订单ID");
                        return;
                    }
                    Intent intent = new Intent(context, PaySucceedActivity.class);
                    intent.putExtra("order_id", orderId + "");
                    intent.putExtra("order_type", orderType);
                    context.startActivity(intent);
                } else if (payID == 6) {
                    Intent intent = new Intent(context, ShopPayActivity.class);
                    intent.putExtra("order_id", orderId + "");
                    intent.putExtra("orderType", orderType + "");
                    context.startActivity(intent);
                }

            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    private void dealOrderPX(Context context, String orderSn) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderSn)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderNumber", orderSn);
            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            final OrderDeletePXApi orderDeletePXApi = new OrderDeletePXApi(mineOrderActivity, simpleOnNextListenerDetlOrderPX);
            orderDeletePXApi.setCache(false);
            orderDeletePXApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(orderDeletePXApi);

        }
    }

    private void cancleOrderPX(final Context context, final String orderSn) {


        DialogCustom.showDoubleDialog(context, "提示", "您确定要取消订单吗？", "取消", "确定", new DialogCustom.CustomDialogDouble() {
            @Override
            public void rightButtonClicked() {
                cancleOrderReqPX(context, orderSn, SELECT_CHECK);
            }

            @Override
            public void leftButtonClicked() {

            }
        });
    }

    private void orderFinish(Context context, String orderId) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderId)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderId", orderId);
            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());


            final OrderFinishApi orderFinishApi = new OrderFinishApi(mineOrderActivity, simpleOnNextListenerOrderFinish);
            orderFinishApi.setCache(false);
            orderFinishApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(orderFinishApi);

        }
    }

    private void againBuyResq(Context context, String orderId) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderId)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderId", orderId);
            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());


            final BuyAgainApi buyAgainApi = new BuyAgainApi(mineOrderActivity, simpleOnNextListenerBuyAgain);
            buyAgainApi.setCache(false);
            buyAgainApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(buyAgainApi);

        }
    }

    private void lookWuLiu(Context context, String orderId) {
        if (!SharedPreferencesUtil.getInstance(context).getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderId)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderId", orderId);
            final BaseActivity mineOrderActivity = (BaseActivity) context;
            final GetOrderTracesApi getOrderTracesApi = new GetOrderTracesApi(mineOrderActivity, simpleOnNextListenerLookWuliu);
            getOrderTracesApi.setCache(false);
            getOrderTracesApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(getOrderTracesApi);

        }
    }

    private void dealOrder(Context context, String orderId) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderId)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderId", orderId);
            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            final OrderDeleteApi orderDeleteApi = new OrderDeleteApi(mineOrderActivity, simpleOnNextListenerDetlOrder);
            orderDeleteApi.setCache(false);
            orderDeleteApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(orderDeleteApi);

        }
    }


    private void commonPop(View view) {
        popupWindow = new PopupWindow(view, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
        final BaseActivity baseActivity = (BaseActivity) context;
        // 产生背景变暗效果
        WindowManager.LayoutParams lp = baseActivity.getWindow()
                .getAttributes();
        lp.alpha = 0.4f;
        baseActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        baseActivity.getWindow().setAttributes(lp);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(false);
        popupWindow.setTouchable(true);
        //从下往上弹出动画效果
        popupWindow.setAnimationStyle(R.style.bottomPopupAnimation);
        popupWindow.showAtLocation(baseActivity.findViewById(R.id.ll_root), Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            // 在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = baseActivity.getWindow()
                        .getAttributes();
                lp.alpha = 1f;
                baseActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                baseActivity.getWindow().setAttributes(lp);
            }
        });
    }

    private void cancleOrder(final Context context, final String orderID) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.cancle_order_pop, null);
        rl_close = inflate.findViewById(R.id.rl_close);
        iv_goods_error = inflate.findViewById(R.id.iv_goods_error);
        rl_goods_error = inflate.findViewById(R.id.rl_goods_error);
        iv_fapiao_error = inflate.findViewById(R.id.iv_fapiao_error);
        rl_fapiao_error = inflate.findViewById(R.id.rl_fapiao_error);
        iv_not = inflate.findViewById(R.id.iv_not);
        rl_not = inflate.findViewById(R.id.rl_not);
        iv_qita = inflate.findViewById(R.id.iv_qita);
        rl_qita = inflate.findViewById(R.id.rl_qita);
        tv_kaolv = inflate.findViewById(R.id.tv_kaolv);
        tv_submit = inflate.findViewById(R.id.tv_submit);
        commonPop(inflate);
        rl_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        rl_goods_error.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_goods_error.setSelected(true);
                iv_fapiao_error.setSelected(false);
                iv_not.setSelected(false);
                iv_qita.setSelected(false);
                SELECT_CHECK = 1;
                tv_submit.setBackgroundResource(R.drawable.shape_right_r20_green);
            }
        });
        rl_fapiao_error.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_goods_error.setSelected(false);
                iv_fapiao_error.setSelected(true);
                iv_not.setSelected(false);
                iv_qita.setSelected(false);
                SELECT_CHECK = 2;
                tv_submit.setBackgroundResource(R.drawable.shape_right_r20_green);
            }
        });
        rl_not.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_goods_error.setSelected(false);
                iv_fapiao_error.setSelected(false);
                iv_not.setSelected(true);
                iv_qita.setSelected(false);
                SELECT_CHECK = 3;
                tv_submit.setBackgroundResource(R.drawable.shape_right_r20_green);
            }
        });
        rl_qita.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_goods_error.setSelected(false);
                iv_fapiao_error.setSelected(false);
                iv_not.setSelected(false);
                iv_qita.setSelected(true);
                SELECT_CHECK = 4;
                tv_submit.setBackgroundResource(R.drawable.shape_right_r20_green);
            }
        });
        tv_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancleOrderReq(context, orderID, SELECT_CHECK);

            }
        });
        tv_kaolv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

    }

    private void cancleOrderReqPX(Context context, String orderSn, int select_check) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;

        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderSn)) {
                ToastTools.showToast(context, "没有订单编号");
                return;
            }
            map.put("orderNumber", orderSn);

            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());

            final OrderCancelPXApi orderCancelPXApi = new OrderCancelPXApi(mineOrderActivity, simpleOnNextListenerCancleOrderPX);
            orderCancelPXApi.setCache(false);
            orderCancelPXApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(orderCancelPXApi);

        }

    }

    private void cancleOrderReq(Context context, String orderId, int type) {
        final BaseActivity mineOrderActivity = (BaseActivity) context;
        if (!mineOrderActivity.getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            if (TextUtils.isEmpty(orderId)) {
                ToastTools.showToast(context, "没有订单ID");
                return;
            }
            map.put("orderId", orderId);
            map.put("token", mineOrderActivity.getSharedPreferencesUtil().getLogintoken());
            map.put("type", type + "");

            final OrderCancelApi orderCancelApi = new OrderCancelApi(mineOrderActivity, simpleOnNextListenerCancleOrder);
            orderCancelApi.setCache(false);
            orderCancelApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(orderCancelApi);

        }
    }

    private void addCar(String skuStr, String orderType) {
        if (!SharedPreferencesUtil.getInstance(context).getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            map.put("skuStr", skuStr);
            map.put("orderType", orderType);
//            是否再次购买（0/1）
            map.put("buyAgain", "1");
            map.put("token", SharedPreferencesUtil.getInstance(context).getLogintoken());
            map.put("deviceId", DeviceUtils.getIMEString(context));
            final BaseActivity mineOrderActivity = (BaseActivity) context;
            final AddCarApi addCarApi = new AddCarApi(mineOrderActivity, simpleOnNextListenerAddCar);
            addCarApi.setCache(false);
            addCarApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(addCarApi);
        }
    }

    //取消订单
    HttpOnNextListener simpleOnNextListenerCancleOrder = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            ToastTools.showToast(context, "取消订单成功");
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.CANCEL_ORDER_INFORM);
            EventBus.getDefault().post(informUpdate);
            popupWindow.dismiss();
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //培训取消订单
    HttpOnNextListener simpleOnNextListenerCancleOrderPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            ToastTools.showToast(context, "取消订单成功");
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.CANCEL_ORDER_INFORM);
            EventBus.getDefault().post(informUpdate);
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //删除订单
    HttpOnNextListener simpleOnNextListenerDetlOrder = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.DELETE_ORDER_INFORM);
            EventBus.getDefault().post(informUpdate);

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //培训删除订单
    HttpOnNextListener simpleOnNextListenerDetlOrderPX = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            InformUpdate informUpdate = new InformUpdate();
            informUpdate.setEventType(informUpdate.DELETE_ORDER_INFORM);
            EventBus.getDefault().post(informUpdate);

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //查看物流
    HttpOnNextListener simpleOnNextListenerLookWuliu = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };
    //再次购买
    HttpOnNextListener simpleOnNextListenerBuyAgain = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            final BuyAgainBean data = (BuyAgainBean) subjects.getData();
            if (subjects.getCode().equals("0000")) {
                if (data.getOrderType() == 4) {

                    boolean isSkuStr = data.isIsSkuStr();
                    if (subjects.getMsg().length() > 0) {
                        if (isSkuStr) {
                            DialogCustom.showDoubleDialog(context, "提示", subjects.getMsg() + "是否继续再次购买?", "取消", "确定", new DialogCustom.CustomDialogDouble() {
                                @Override
                                public void rightButtonClicked() {
                                    //添加购物车
                                    addCar(data.getSkuStr(), data.getOrderType() + "");

                                }

                                @Override
                                public void leftButtonClicked() {

                                }
                            });
                        } else {
                            ToastTools.showToast(context, subjects.getMsg());
                        }
                    } else {
                        //添加购物车
                        addCar(data.getSkuStr(), data.getOrderType() + "");
                    }
                } else {
                    if (subjects.getMsg().length() > 0) {
                        ToastTools.showToast(context, subjects.getMsg());
                    } else {
                        //跳转确认订单页
                        Intent intent = new Intent(context, OrderConfirmActivity.class);
                        intent.putExtra("orderType", data.getOrderType() + "");
                        intent.putExtra("skuStr", data.getSkuStr());
                        intent.putExtra("againBuy", AGAINBUY);
                        context.startActivity(intent);
                    }
                }
            } else {
                ToastTools.showToast(context, subjects.getMsg());
            }
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //添加购物车
    HttpOnNextListener simpleOnNextListenerAddCar = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }

            //跳转购物车
            Intent intent = new Intent(context, ShoppingCarActivity.class);
            context.startActivity(intent);
        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    //完成订单
    HttpOnNextListener simpleOnNextListenerOrderFinish = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };


    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        context.startActivity(intent);
    }

}
